/*
 * @Author: Jimmy
 * @LastModifiedBy: Jimmy
 * @Date: 2024-02-23 18:41:13
 * @LastEditTime: 2024-02-25 17:47:00
 * @FilePath: /react-vite-admin/src/router/index.tsx
 */
import { Navigate } from "react-router-dom";
import Layout from "../layout";
import { getCache } from "../utils/storage";
import { IRoute } from "./router.types";
import LoginPage from '@/views/login'
import ErrorPage from '@/views/error'

//静态菜单数据
export const staticRouters: IRoute[] = [
    {
        path: '/login',
        label: '登录',
        element: <LoginPage />,
        meta: {
            isAuth: true,
            title: '登录'
        }
    },
    {
        path: '*',
        element: <ErrorPage />,
        meta: {
            isAuth: true,
            title: '404'
        }
    },
]

//配置的同步菜单数据
export const syncRouters: any = (paveRoutes: IRoute[]): IRoute[] => {
    let home = getCache('home');
    let firstPath = '/';
    if (home) {
        firstPath = home.path;
    }
    return [
        {
            path: '',
            element: <Navigate to={firstPath} />,
        },
        {
            path: '/',
            label: "管理后台",
            element: <Layout />,
            meta: {
                isAuth: false,
                title: '管理后台'
            },
            children: (paveRoutes?.length) ? [...paveRoutes] : []
        },
        ...staticRouters
    ]
}